<?php

// --------------------------------------------------------------------- //
// Create Users Table                                                    //
// V1.0 (20020514)                                                       //
// Notes: - This should be done only once                                //
//        - A user 'admin' with password 'changeme' is also created;     //
//          this user acts as a 'root' and should not be deleted.        //
// ----------------------------------------------------------------------//


    $mysqlServer   = "66.226.14.61";
    $mysqlUser     = "timescape";
    $mysqlPassword = "ducati748";
    $mysqlDatabase = "timescape";
    $mysqlTable    = "german";

    $createQuery = "CREATE TABLE $mysqlTable (
                    username  VARCHAR(10)   NOT NULL PRIMARY KEY,
                    password  VARCHAR(10)   NOT NULL,
                    firstname VARCHAR(20)   NOT NULL,
                    surname   VARCHAR(20)   NOT NULL,
                    email     VARCHAR(30)   NOT NULL,
                    company   VARCHAR(20)   NOT NULL,
                    address   VARCHAR(100)  NOT NULL,
                    telephone VARCHAR(20)   NOT NULL,
                    admin     ENUM('N','Y') NOT NULL              DEFAULT 'N',
                    active    ENUM('Y','N') NOT NULL              DEFAULT 'Y',
                    expiry    DATE          NOT NULL              DEFAULT '2002-01-01',
                    module    ENUM('1','2','3') NOT NULL DEFAULT '1')";

    $insertQuery = "INSERT INTO $mysqlTable SET
                    username  = 'admin',
                    password  = 'changeme',
                    firstname = 'Administrator',
                    surname   = 'Account',
                    admin     = 'Y',
                    active    = 'Y',
                    expiry    = '2020-12-31',
                    module    = '3'";

    function outputMessage($message)
    {
        echo '<table width="400" border="0" align="center" cellpadding="0" cellspacing="0" class="winmsg">
                <tr><th>Result:</th></tr>';
        echo "  <tr><td>$message</td></tr>";
        echo "</table>";
        echo "</body>";
        echo "</html>";
        exit;
    }

    echo '<html>';
    echo '  <head>';
    echo '    <title>Create Users Table</title>';
    echo '    <link href="styles.css" rel="stylesheet" type="text/css">';
    echo '  </head>';
    echo '  <body>';

    echo "<h4>Create $mysqlTable Table</h4>";
    echo "<p>INFO: This script will create the '<b>$mysqlTable</b>' table in the '<b>$mysqlDatabase</b>' database using existing MySQL data (host/user/password).</p>";


    $dblink = @mysql_connect($mysqlServer, $mysqlUser, $mysqlPassword);
    if ($dblink == false)
        outputMessage("Unable to connect to database server. Please verify that the server, username and password are correct");
    if (@mysql_select_db($mysqlDatabase) == false)
        outputMessage("Unable to select the database. Please verify that the database actually exists");
    if (@mysql_query($createQuery) == false)
        outputMessage("Unable to create the table. Please verify that it doesn't already exist and that the query is correct.");
    if (@mysql_query($insertQuery) == false)
        outputMessage("Unable to create the administrator. Please verify that it doesn't already exist and that the query is correct.");

    mysql_close($dblink);

    echo '<p>The table was successfully created.</p>
          <p>An Administrator account was also created, which will allow you to add/edit other users.</p>
          <p>To log in, you must enter this info:<br>
         username: admin<br>
         password: changeme<br></p>
         <p><b>NOTE: Please change the default password as soon as possible!</b></p>
         </body>
         </html>';
?>